YUI.add('wfitemmenu', function (Y) {
    var menu = Y.itemMenu =  Y.one("#youxu-item-menu");
    
    menu.hide();
    
    menu.plug(Y.Plugin.NodeMenuNav);
    
    menu.on('click',function(e){
    	e.preventDefault();
    	var mid = e.target.get('id');
    	if(mid)mid = mid.substring(15);
    	if(mid == 'entry-item'){
    		if(Y.sharedMode){
    			Y.showMsg('共享模式下不支持此操作！',2000);
    			return;
    		}
    		if(Y.lastClickedItemId){
    	    	var history = new Y.HistoryHash();
    	    	history.addValue('item',Y.lastClickedItemId);
    	    	menu.hide();
    		}
    		Y.all('.bullet-clicked').removeClass('bullet-clicked');
    	}else if(mid == 'close'){
    		menu.hide();
    		Y.all('.bullet-clicked').removeClass('bullet-clicked');
    		if(Y.lastClickedItemId){
    			Y.lastClickedItemId = null;
    		}
    	}else if(mid == 'cut'){
    		Y.clipBoard = Y.lastClickedItemId;
    		var ctd = Y.one('#project-content--' + Y.clipBoard);
    		ctd.addClass('copied-content');
    		menu.hide();
    		Y.all('.bullet-clicked').removeClass('bullet-clicked');
    	}else if(mid == 'paste-above'){
    		paste(false);
    		Y.all('.bullet-clicked').removeClass('bullet-clicked');
    	}else if(mid == 'paste-bellow'){
    		paste(true);
    		Y.all('.bullet-clicked').removeClass('bullet-clicked');
    	}else if(mid == 'share'){
    		menu.hide();
    		Y.showSharePanel();
    	}
    });
    
    function paste(isBellow){
		menu.hide();
		if(Y.clipBoard){
			var bePasteModel = Y.Wfutils.getModelById(Y.clipBoard);
			var targetModel = Y.Wfutils.getModelById(Y.lastClickedItemId);
			if(bePasteModel && targetModel){
				if(targetModel.get('path').indexOf(bePasteModel.get('id')) != -1){
					return;
				}
    			var dp = targetModel.get('dp'),
    				pdp = bePasteModel.get('dp');
    			var list  = Y.projectListList[dp],
    				plist = Y.projectListList[pdp];
    			var order = isBellow ? list.nextPosition(targetModel) : list.prevPosition(targetModel);
    			plist.remove(bePasteModel);
    			bePasteModel.setAttrs({path:targetModel.get('path'),dp:dp,position:order}).save();
    			list.add(bePasteModel);
			}
			Y.clipBoard = null;
		}
		Y.all('.copied-content').removeClass('copied-content');
    }

    //    Show the menu now that it is ready

    menu.get("ownerDocument").get("documentElement").removeClass("yui3-loading");
    
},'0.0.1',{requires:['node-menunav', 'node-menunav-core-css', 'custommenunavskin','transition']});